# -*- coding:utf8 -*-
#encoding = utf-8
__author__ = 'man' 

#		_________________________________________________________________________________
#
#						漫鸽网络技术服务(mangenotwork)拥有所有权
#						@www.hbsj.xyz   
#						@www.mangenotwork.com
#			严重声明：原始代码属于"漫鸽网络技术服务(mangenotwork)"的知识产权，拥有法律的保护，
#		请勿抄袭、转载、删除、私用、篡改、破坏...
#
#       
#		简介 ：  compress_img.py 图片处理与存放位置API
#		作者 ： 李漫(man)
#		创建时间:  20190708
#		
#		_________________________________________________________________________________


#pip install Image
from PIL import Image
import api.public as pub

#头像存放位置
head_imgpath = pub.HEAD_IMG_Main_Path()

#社区发布的信息图片存放位置
info_imgpath = pub.INFO_IMG_Main_Path()

#允许图片类型
ALLOWED_EXTENSIONS = set(['jpg', 'png','jpeg','JPG', 'PNG','JPEG'])



#图片压缩函数 1
def compressImg_1(imgfile,imgname,imgdis):
	save_path = "C:/Users/Administrator/Desktop/"
	img_obj_500 = Image.open(imgfile)
	img_obj_1200 = Image.open(imgfile)
	# 500px
	img_obj_500.thumbnail((500,500))
	img_obj_1200.thumbnail((1200,1200))
	#
	new_path_500 = save_path + imgname+"_500."+imgdis
	img_obj_500.save(new_path_500)
	new_path_1200 = save_path + imgname+"_1200."+imgdis
	img_obj_1200.save(new_path_1200)


#compressImg_1("C:/Users/Administrator/Desktop/QQ图片20190628145109.jpg",'QQ图片20190628145109','jpg')



#图片压缩函数 头像  像素为  210px * 210px
def compressImg_2(imgfile,imgname,imgdis):
	save_path = head_imgpath
	img_obj_300 = Image.open(imgfile)
	# 500px
	img_obj_300.thumbnail((210,210))
	#
	new_path_300 = save_path + imgname+"_300."+imgdis
	new_name = imgname+"_300."+imgdis
	img_obj_300.save(new_path_300)
	return new_name


#发布内容的图片  1000px * 1000px
def compressImg_1000(imgfile,imgname,imgdis):
	save_path = info_imgpath
	img_obj_300 = Image.open(imgfile)

	# 500px
	#img_obj_300.thumbnail((1000,1000))
	img_obj_300.thumbnail((800,800))
	#
	new_path_300 = save_path + imgname+"_1000."+imgdis
	new_name = imgname+"_1000."+imgdis
	img_obj_300.save(new_path_300)
	return new_name


#compressImg_2("C:/Users/Administrator/Desktop/QQ图片20190628145109.jpg",'QQ图片20190628145109','jpg')



#验证文件类型
def allowed_file(filename):
    return '.' in filename and filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS

#获取文件后缀
def get_filedis(filename):
	return filename.rsplit('.')[-1]







